﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.Web.UI;
using System.Collections;

namespace DR5.SPExtend
{
    public static class ICollectionExtension
    {
        public static string CommaSeparatedString(this ICollection coll, string seprationStr)
        {
            string str = string.Empty;
            foreach (object obj in coll)
            {
                str += obj.ToString() + seprationStr;
            }
            return str;
        }

        /// <summary>
        /// Check the object in collection by loop.
        /// </summary>
        /// <param name="col"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool Exist(this ICollection col, object key)
        {
            foreach (object str in col)
            {
                if (str == key || str.Equals(key))
                {
                    return true;
                }
            }
            return false;
        }

        public static ControlCollection Adds(this ControlCollection col, Control con)
        {
            col.Add(con);
            return col;
        }

        public static ListItemCollection Adds(this ListItemCollection col, string item)
        {
            col.Add(item); return col;
        }

        public static StringDictionary Adds(this StringDictionary col, string key, string value)
        {
            col.Add(key, value); return col;
        }
    }
}
